<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;

class CompanyModel extends BaseModel
{
    use HasFactory;
    protected $table = 'company';
    protected $fillable = [
        'name',
        'short_name',
        'parent_id',
        'type',
        'end_date',
        'address',
        'logo',
        'contact_user',
        'contact_phone',
        'status'
    ];

    public static function page($keywords) {
        // 这里加了status判断，输出就没有数据了，这是个bug
        $query = self::where('status', '<', 2)->orderBy('id', 'desc');
  
        if ($keywords) {
            $keywords = trim($keywords);
            $query->where('name', 'like', '%' . $keywords . '%');
        }
        return  $query->paginate(15);
    }

    public static function add($data) {
        return self::create($data);
    }
}
